<?php

use Illuminate\Http\Request;

$api = app('Dingo\Api\Routing\Router');

$api->version('v1',[
    'namespace' => 'App\Http\Controllers',
    'middleware' => [
        'api',
        'cors'
    ]
],function ($api)
{
    $api->get('test', 'TwilioController@test');
    $api->get('xml', 'TwilioController@responesXml')->name('xml');  //twilio的XML
    $api->post('plivo/xml', 'PlivoController@sendResponseWithPlivo');  //plivo的XML
    $api->post('record', 'TwilioController@record')->name('record');
    $api->post('voice', 'TwilioController@voice')->name('voice');
    $api->any('plivo/record', 'PlivoController@record'); //Plivo 结束通话记录 3
    $api->post('plivo/video', 'PlivoController@video');  //Plivo 保持通话记录 2
    $api->get('plivo/videoUrl', 'PlivoController@videoUrl');  //Plivo 录音地址 1
    $api->get('plivo/index', 'PlivoController@index');

    $api->post('plivo/hangup', 'PlivoController@hangup');   //挂断
    // 认证登录
    $api->post('login', 'AuthController@login')->middleware('log')->name('api.auth.login');
    $api->group(['middleware' => ['api','auth:api','log']], function ($api) {
        $api->post('logout', 'AuthController@logout')->name('api.auth.logout');
        $api->post('refresh', 'AuthController@refresh');
        $api->post('currentUser', 'AuthController@currentUser');
        $api->get('currentPermissions', 'AuthController@currentPermissions');
        $api->patch('auth/password/reset', 'AuthController@update')->name('api.password.reset');
    });
    // 其他路由组
    $api->group(['middleware' => ['api','auth:api','log']], function ($api) {
        $api->get('roles', 'RoleController@index')->middleware('permission:api.role.index')->name('api.role.index');
        $api->post('roles', 'RoleController@store')->middleware('permission:api.role.store')->name('api.role.store');
        $api->get('roles/{role}', 'RoleController@show')->middleware('permission:api.role.show')->name('api.role.show');
        $api->patch('roles/{role}', 'RoleController@update')->middleware('permission:api.role.update')->name('api.role.update');
        $api->delete('roles/{role}', 'RoleController@destroy')->middleware('permission:api.role.destroy')->name('api.role.destroy');
        $api->get('roles/{role}/children', 'RoleController@children')->name('api.role.children');
        $api->get('roles/{role}/permissions', 'RoleController@rolePermissions')->name('api.role.permissions.index');
        $api->patch('roles/{role}/permissions', 'RoleController@rolePermissionsUpdate')->middleware('permission:api.role.permissions.update')->name('api.role.permissions.update');
        //user
        $api->get('users', 'UserController@index')->name('api.user.index');
        $api->get('users/index', 'UserController@userIndex')->middleware('permission:api.userIndex.index')->name('api.userIndex.index'); //导入列表
        $api->get('users/show', 'UserController@userFsUserShow')->middleware('permission:api.userFsUserShow.show')->name('api.userFsUserShow.show'); //导入详情
        $api->get('users/task/index', 'UserController@index')->name('api.user.index'); //人员列表无权限访问
        $api->post('users', 'UserController@store')->middleware('permission:api.user.store')->name('api.user.store');
        $api->get('users/{user}', 'UserController@show')->middleware('permission:api.user.show')->name('api.user.show');
        $api->patch('users/{user}', 'UserController@update')->middleware('permission:api.user.update')->name('api.user.update');
        $api->delete('users/{user}', 'UserController@destroy')->middleware('permission:api.user.destroy')->name('api.user.destroy');
        $api->post('users/batch/delete', 'UserController@destroy')->middleware('permission:api.user.destroy.batch')->name('api.user.destroy.batch');
        $api->post('users/{user}/bind', 'UserController@bindPhone')->middleware('permission:api.user.phone.bind')->name('api.user.phone.bind'); //电话绑定
        $api->post('users/{user}/unbind', 'UserController@unbindPhone')->name('api.user.phone.unbind');
        //excel
        $api->post('users/import', 'UserController@import')->middleware('permission:api.userFsUserShow.import')->name('api.userFsUserShow.import'); //会员导入
        $api->get('export', 'FsUserController@export')->middleware('permission:api.fsuser.export')->name('api.fsuser.export'); //会员资料导出
        $api->get('record/export', 'PhoneRecordController@export')->middleware('permission:api.record.export')->name('api.record.export'); //通话记录导出
        //permission
        $api->get('permissions', 'PermissionController@index')->name('api.permission.index');
        //twilo
        $api->get('buyNumber', 'TwilioController@buyNumber')->name('api.buy.number');
        $api->get('phone', 'PhoneController@index')->name('api.phone.index');
        $api->get('token', 'TwilioController@token')->name('api.phone.dial');
        //plivo
        $api->get('plivo', 'PlivoController@index')->name('api.plivo.index');
        //sms
        $api->post('sms/send', 'SmsController@send')->name('api.sms.send');
        $api->post('sms/send/batch', 'SmsController@sendMore')->name('api.sms.send.batch');
        //PhoneRecord []
        $api->get('record', 'PhoneRecordController@index')->middleware(['permission:api.record.index.all'])->name('api.record.index.all');  //所有通话录音
        $api->get('record/current', 'PhoneRecordController@currentIndex')->name('api.record.index'); //当前通话录音
        //SmsRecord
        $api->get('smsRecord', 'SmsRecordController@index')->middleware(['permission:api.smsRecord.index.all'])->name('api.smsRecord.index.all'); //所有短信记录
        $api->get('smsRecord/current', 'SmsRecordController@currIndex')->name('api.smsRecord.index');  //当前短信记录
        //FsUser
        $api->post('fsuser', 'FsUserController@index')->middleware(['permission:api.fsuser.index|api.fsuser.index.all'])->name('api.fsuser.index'); //查看会员资料
        $api->get('fsuser/{fsUser}/im', 'FsUserController@userImIndex')->name('api.fsuser.user.im');    //添加会员微信列表
        //FsUser下面的记录
        $api->get('fsuser/{fsUser}/remark', 'FsUserController@remark')->name('api.fsuser.remark');
        $api->get('fsuser/{fsUser}/record', 'FsUserController@record')->name('api.fsuser.record');
        $api->get('fsuser/{fsUser}/cash', 'FsUserController@cash')->name('api.fsuser.record');
        $api->get('fsuser/{fsUser}/im', 'FsUserController@userIm')->name('api.fsuser.im');
        $api->get('fsuser/{fsUser}/users', 'FsUserController@users')->name('api.fsuser.user');
        //log
        $api->get('log', 'LogController@index')->name('api.log.index.all');
        //ip
        $api->get('ip', 'IpController@index')->middleware('permission:api.ip.index')->name('api.ip.index');
        $api->post('ip', 'IpController@store')->middleware('permission:api.ip.store')->name('api.ip.store');
        $api->patch('ip/{ip}', 'IpController@edit')->middleware('permission:api.ip.update')->name('api.ip.update');
        $api->delete('ip/{ip}', 'IpController@destroy')->middleware('permission:api.ip.destroy')->name('api.ip.destroy');
        $api->get('ip/enabled', 'IpController@ipEnabled')->middleware('permission:api.ip.ipEnabled')->name('api.ip.ipEnabled');
        $api->get('ip/enabled/index', 'IpController@ipEnabledIndex')->name('api.ip.ipEnabledIndex');

        $api->get('regionIndex', 'SettingController@regionIndex')->name('api.setting.regionIndex');
        $api->get('regionTimeIndex', 'SettingController@regionTimeIndex')->name('api.setting.regionTimeIndex');
        //setting
        $api->get('setting/sync/{phoneSetting}', 'SettingController@sync')->name('api.setting.sync');
        $api->get('phone/balance/{phoneSetting}', 'SettingController@phoneBalanceSync')->name('api.setting.phoneBalanceSync');
        $api->post('phone/setting', 'SettingController@phoneSetting')->middleware('permission:api.phoneSetting.store')->name('api.phoneSetting.store');
        $api->get('phone/setting', 'SettingController@phoneIndex')->middleware('permission:api.phoneSetting.index')->name('api.phoneSetting.index');
        $api->patch('phone/setting/{phoneSetting}', 'SettingController@phoneSiteUpdate')->middleware('permission:api.phoneSetting.update')->name('api.phoneSetting.update');
        $api->get('phone/setting/status/{phoneSetting}', 'SettingController@phoneStatus')->middleware('permission:api.phoneSetting.status')->name('api.phoneSetting.status');
        $api->delete('phone/setting/{phoneSetting}', 'SettingController@phoneDestroy')->middleware('permission:api.phoneSetting.destroy')->name('api.phoneSetting.destroy');
        $api->post('sms/setting', 'SettingController@SmsSetting')->middleware('permission:api.smsSetting.store')->name('api.smsSetting.store');
        $api->patch('sms/setting/{smsSetting}', 'SettingController@SmsSiteUpdate')->middleware('permission:api.smsSetting.update')->name('api.smsSetting.update');
        $api->get('sms/setting/{smsSetting}', 'SettingController@SmsStatus')->middleware('permission:api.smsSetting.status')->name('api.smsSetting.status');
        $api->delete('sms/setting/{smsSetting}', 'SettingController@SmsDestroy')->middleware('permission:api.smsSetting.destroy')->name('api.smsSetting.destroy');
        $api->get('sms/setting', 'SettingController@smsIndex')->middleware('permission:api.smsSetting.index')->name('api.smsSetting.index');
        //Im
        $api->get('bind/fsUser/im/index', 'ImController@bindFsUserIndex')->name('api.im.bind.fsUser');
        $api->get('im', 'ImController@index')->middleware('permission:api.im.index')->name('api.im.index');
        $api->post('im', 'ImController@store')->middleware('permission:api.im.store')->name('api.im.store');
        $api->get('im/{im}', 'ImController@show')->middleware('permission:api.im.show')->name('api.im.show');
        $api->patch('im/{im}', 'ImController@update')->middleware('permission:api.im.update')->name('api.im.update');
        $api->delete('im/{im}', 'ImController@destroy')->middleware('permission:api.im.destroy')->name('api.im.destroy');
        //FsUserIm
        $api->get('fsUser/im', 'FsUserImController@index')->name('api.fsUser.im.index');
        $api->post('fsUser/im', 'FsUserImController@store')->name('api.fsUser.im.store');
        $api->patch('fsUser/im', 'FsUserImController@update')->name('api.fsUser.im.update');
        //FsUserHasIm
        $api->post('fsUserHasIm', 'FsUserHasImController@store')->name('api.fsUserHasIm.store');
        $api->patch('fsUserHasIm', 'FsUserHasImController@update')->name('api.fsUserHasIm.update');
        //FsUserPhone
        $api->post('fsUser/phone', 'FsUserPhoneController@store')->name('api.fsUserPhone.store');
        $api->get('fsUser/phone', 'FsUserPhoneController@index')->name('api.fsUserPhone.index');
        //Level
        $api->post('level', 'LevelController@store')->middleware('permission:api.level.store')->name('api.level.store');
        $api->get('level', 'LevelController@index')->middleware('permission:api.level.index')->name('api.level.index');
        $api->patch('level/{level}', 'LevelController@update')->middleware('permission:api.levelevel.update')->name('api.levelevel.update');
        $api->delete('level/{level}', 'LevelController@destroy')->middleware('permission:api.level.destroy')->name('api.level.destroy');
        $api->post('fsUser/level', 'LevelController@fsUserLevelAdd')->name('api.fsUser.level.store');
        //FsUserRemark
        $api->get('fsUser/remark/{fs_user_remark}', 'FsUserRemarkController@show')->name('api.fsUserRemark.show');
        $api->get('fsUser/remark', 'FsUserRemarkController@index')->name('api.fsUserRemark.index');
        $api->post('fsUser/remark', 'FsUserRemarkController@store')->name('api.fsUserRemark.store');
        $api->patch('fsUser/remark/{fs_user_remark}', 'FsUserRemarkController@update')->name('api.fsUserRemark.update');
        $api->delete('fsUser/remark/{fs_user_remark}', 'FsUserRemarkController@destroy')->name('api.fsUserRemark.destroy');
        //RecordRemark
        $api->get('record/remark', 'RecordRemarkController@index')->name('api.RecordRemark.index');
        $api->get('record/remark/{recordRemark}', 'RecordRemarkController@show')->name('api.RecordRemark.show');
        $api->post('record/remark', 'RecordRemarkController@store')->name('api.RecordRemark.store');
        $api->patch('record/remark/{recordRemark}', 'RecordRemarkController@update')->name('api.RecordRemark.update');
        $api->delete('record/remark/{recordRemark}', 'RecordRemarkController@destroy')->name('api.RecordRemark.destroy');
        //Task
        $api->get('task', 'TaskController@index')->middleware('permission:api.task.index.all')->name('api.task.index.all');  //所有任务列表
        $api->get('task/current', 'TaskController@currentIndex')->name('api.task.currentIndex');  //当前任务列表
        $api->get('task/{task}', 'TaskController@show')->name('api.task.show');
        $api->post('task', 'TaskController@store')->middleware('permission:api.task.store')->name('api.task.store');
        $api->patch('task/{task}', 'TaskController@update')->middleware('permission:api.task.update')->name('api.task.update');
        $api->delete('task/{task}', 'TaskController@destroy')->middleware('permission:api.task.destroy')->name('api.task.destroy');
        $api->delete('remove/task/fsUser', 'TaskController@removeFsUser')->middleware('permission:api.task.remove')->name('api.task.remove');  //单个解除会员维护关系
        $api->delete('remove/patch/task/fsUser', 'TaskController@patchRemoveFsUser')->middleware('permission:api.task.remove.patch')->name('api.task.remove.patch');  //批量解除会员维护关系
        $api->delete('remove/all/task/fsUser', 'TaskController@allRemoveFsUser')->middleware('permission:api.task.remove.patch')->name('api.task.remove.all');  //通过会员id解除所有
        //Book
        $api->post('book', 'BookController@store')->name('api.book.store');
        $api->get('book', 'BookController@index')->name('api.book.index');
        $api->delete('book', 'BookController@destroy')->name('api.book.destroy');
        //Home
        $api->get('home', 'HomeController@index')->name('api.home.index');
        //Statistic
        $api->get('sectionVisits', 'StatisticDataController@sectionVisits')->middleware('permission:api.sectionVisits')->name('api.sectionVisits');//获取部门回访效果
        $api->get('customVisits', 'StatisticDataController@customVisits')->middleware('permission:api.customVisits')->name('api.customVisits');//获取单人回访效果
        $api->get('personalGrade', 'StatisticDataController@personalGrade')->name('api.personalGrade');//我的绩效和整体绩效
        $api->get('personalRecentTasks', 'StatisticDataController@personalRecentTasks')->name('api.personalRecentTasks');//近七天任务
    });
});
